package com.example.hotelsystem.service.impl;

import code.CodeError;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.hotelsystem.entity.Checkin;
import com.example.hotelsystem.entity.City;
import com.example.hotelsystem.entity.HotelName;
import com.example.hotelsystem.entity.Room;
import com.example.hotelsystem.mapper.CheckinMapper;
import com.example.hotelsystem.page.Pagesize;
import com.example.hotelsystem.result.Result;
import com.example.hotelsystem.service.CheckinService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.hotelsystem.service.CityService;
import com.example.hotelsystem.service.HotelNameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lee
 * @since 2020-10-14
 */
@Service
public class CheckinServiceImpl extends ServiceImpl<CheckinMapper, Checkin> implements CheckinService {

    @Autowired
    HotelNameService hotelNameService;
    @Autowired
    CityService cityService;
    @Autowired
    CheckinService checkinService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result checkinList(Integer currentPage){
        Page page = new Page(currentPage, Pagesize.pageSize1);
        IPage<Checkin> checkinList=checkinService.page(page);
        if(checkinList!=null){
            for(Checkin item : checkinList.getRecords()){
                City c = cityService.getById(item.getCityId());
                HotelName n = hotelNameService.getById(item.getHotelId());
                item.setHotelName(n.getHotelName());
                item.setCityName(c.getCityName());
            }
            return Result.success(checkinList);
        }
        return Result.error(CodeError.CHECKIN_LIST_NULL,"入住列表为空");
    }

}
